package com.qipay.baas.mapper;

import com.qipay.baas.model.Sp;
import com.qipay.baas.model.SpExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.type.JdbcType;

public interface SpMapper {
    @DeleteProvider(type=SpSqlProvider.class, method="deleteByExample")
    int deleteByExample(SpExample example);

    @Delete({
        "delete from sp",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into sp (mch_id, card_no, ",
        "delete_flag, `name`, ",
        "service, bank, factory_class_name, ",
        "update_date, create_date, ",
        "`state`, fail_reason, ",
        "sp_user_name, zfb_no)",
        "values (#{mchId,jdbcType=VARCHAR}, #{cardNo,jdbcType=VARCHAR}, ",
        "#{deleteFlag,jdbcType=TINYINT}, #{name,jdbcType=VARCHAR}, ",
        "#{service,jdbcType=VARCHAR}, #{bank,jdbcType=VARCHAR}, #{factoryClassName,jdbcType=VARCHAR}, ",
        "#{updateDate,jdbcType=TIMESTAMP}, #{createDate,jdbcType=TIMESTAMP}, ",
        "#{state,jdbcType=TINYINT}, #{failReason,jdbcType=VARCHAR}, ",
        "#{spUserName,jdbcType=VARCHAR}, #{zfbNo,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(Sp record);

    @InsertProvider(type=SpSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(Sp record);

    @SelectProvider(type=SpSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="mch_id", property="mchId", jdbcType=JdbcType.VARCHAR),
        @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="delete_flag", property="deleteFlag", jdbcType=JdbcType.TINYINT),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="service", property="service", jdbcType=JdbcType.VARCHAR),
        @Result(column="bank", property="bank", jdbcType=JdbcType.VARCHAR),
        @Result(column="factory_class_name", property="factoryClassName", jdbcType=JdbcType.VARCHAR),
        @Result(column="update_date", property="updateDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="fail_reason", property="failReason", jdbcType=JdbcType.VARCHAR),
        @Result(column="sp_user_name", property="spUserName", jdbcType=JdbcType.VARCHAR),
        @Result(column="zfb_no", property="zfbNo", jdbcType=JdbcType.VARCHAR)
    })
    List<Sp> selectByExampleWithRowbounds(SpExample example, RowBounds rowBounds);

    @SelectProvider(type=SpSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="mch_id", property="mchId", jdbcType=JdbcType.VARCHAR),
        @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="delete_flag", property="deleteFlag", jdbcType=JdbcType.TINYINT),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="service", property="service", jdbcType=JdbcType.VARCHAR),
        @Result(column="bank", property="bank", jdbcType=JdbcType.VARCHAR),
        @Result(column="factory_class_name", property="factoryClassName", jdbcType=JdbcType.VARCHAR),
        @Result(column="update_date", property="updateDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="fail_reason", property="failReason", jdbcType=JdbcType.VARCHAR),
        @Result(column="sp_user_name", property="spUserName", jdbcType=JdbcType.VARCHAR),
        @Result(column="zfb_no", property="zfbNo", jdbcType=JdbcType.VARCHAR)
    })
    List<Sp> selectByExample(SpExample example);

    @Select({
        "select",
        "id, mch_id, card_no, delete_flag, `name`, service, bank, factory_class_name, ",
        "update_date, create_date, `state`, fail_reason, sp_user_name, zfb_no",
        "from sp",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="mch_id", property="mchId", jdbcType=JdbcType.VARCHAR),
        @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="delete_flag", property="deleteFlag", jdbcType=JdbcType.TINYINT),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="service", property="service", jdbcType=JdbcType.VARCHAR),
        @Result(column="bank", property="bank", jdbcType=JdbcType.VARCHAR),
        @Result(column="factory_class_name", property="factoryClassName", jdbcType=JdbcType.VARCHAR),
        @Result(column="update_date", property="updateDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="fail_reason", property="failReason", jdbcType=JdbcType.VARCHAR),
        @Result(column="sp_user_name", property="spUserName", jdbcType=JdbcType.VARCHAR),
        @Result(column="zfb_no", property="zfbNo", jdbcType=JdbcType.VARCHAR)
    })
    Sp selectByPrimaryKey(Long id);

    @UpdateProvider(type=SpSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Sp record, @Param("example") SpExample example);

    @UpdateProvider(type=SpSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Sp record, @Param("example") SpExample example);

    @UpdateProvider(type=SpSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Sp record);

    @Update({
        "update sp",
        "set mch_id = #{mchId,jdbcType=VARCHAR},",
          "card_no = #{cardNo,jdbcType=VARCHAR},",
          "delete_flag = #{deleteFlag,jdbcType=TINYINT},",
          "`name` = #{name,jdbcType=VARCHAR},",
          "service = #{service,jdbcType=VARCHAR},",
          "bank = #{bank,jdbcType=VARCHAR},",
          "factory_class_name = #{factoryClassName,jdbcType=VARCHAR},",
          "update_date = #{updateDate,jdbcType=TIMESTAMP},",
          "create_date = #{createDate,jdbcType=TIMESTAMP},",
          "`state` = #{state,jdbcType=TINYINT},",
          "fail_reason = #{failReason,jdbcType=VARCHAR},",
          "sp_user_name = #{spUserName,jdbcType=VARCHAR},",
          "zfb_no = #{zfbNo,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Sp record);
}